home *** CD-ROM | disk | FTP | other *** search
/ X User Tools / X User Tools (O'Reilly and Associates)(1994).ISO / sun4c / archive / tcltk.z / tcltk / man / cat3 / GetBitmap.3 < prev    next >
Text File  |  1994-09-20  |  11KB  |  331 lines

  1.  
  2.  
  3.  
  4. Tk_GetBitmap(3)       Tk Library Procedures
  5.  
  6.  
  7.  
  8. _________________________________________________________________
  9.  
  10. NAME
  11.      Tk_GetBitmap,       Tk_DefineBitmap,        Tk_NameOfBitmap,
  12.      Tk_SizeOfBitmap, Tk_FreeBitmap, Tk_GetBitmapFromData - main-
  13.      tain database of single-plane pixmaps
  14.  
  15. SYNOPSIS
  16.      #include <tk.h>
  17.  
  18.      Pixmap
  19.      Tk_GetBitmap(_i_n_t_e_r_p, _t_k_w_i_n, _i_d)
  20.  
  21.      int                                                           |
  22.      Tk_DefineBitmap(_i_n_t_e_r_p, _n_a_m_e_I_d, _s_o_u_r_c_e, _w_i_d_t_h, _h_e_i_g_h_t)        |
  23.  
  24.      Tk_Uid
  25.      Tk_NameOfBitmap(_d_i_s_p_l_a_y, _b_i_t_m_a_p)                              |
  26.  
  27.      Tk_SizeOfBitmap(_d_i_s_p_l_a_y, _b_i_t_m_a_p, _w_i_d_t_h_P_t_r, _h_e_i_g_h_t_P_t_r)         |
  28.  
  29.      Tk_FreeBitmap(_d_i_s_p_l_a_y, _b_i_t_m_a_p)                                |
  30.  
  31. ARGUMENTS
  32.      Tcl_Interp      *_i_n_t_e_r_p     (in)      Interpreter to use for
  33.                                            error reporting.
  34.  
  35.      Tk_Window       _t_k_w_i_n       (in)      Token  for  window  in
  36.                                            which  the bitmap will
  37.                                            be used.
  38.  
  39.      Tk_Uid          _i_d          (in)      Description of bitmap;
  40.                                            see below for possible
  41.                                            values.
  42.  
  43.      Tk_Uid          *_n_a_m_e_I_d     (in)      Name for new bitmap to
  44.                                            be defined.
  45.  
  46.      char            *_s_o_u_r_c_e     (in)      Data  for  bitmap,  in
  47.                                            standard  bitmap  for-
  48.                                            mat.  Must  be  stored
  49.                                            in static memory whose
  50.                                            value    will    never
  51.                                            change.
  52.  
  53.      unsigned int    _w_i_d_t_h       (in)      Width of bitmap.
  54.  
  55.      unsigned int    _h_e_i_g_h_t      (in)      Height of bitmap.
  56.  
  57.      unsigned int    *_w_i_d_t_h_P_t_r   (out)     Pointer  to  word   to
  58.                                            fill  in with _b_i_t_m_a_p's
  59.                                            width.
  60.  
  61.  
  62.  
  63. Tk                                                              1
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70. Tk_GetBitmap(3)       Tk Library Procedures
  71.  
  72.  
  73.  
  74.      unsigned int    *_h_e_i_g_h_t_P_t_r  (out)     Pointer  to  word   to
  75.                                            fill  in with _b_i_t_m_a_p's
  76.                                            height.
  77.  
  78.      Display         *_d_i_s_p_l_a_y    (in)      Display for which _b_i_t_-
  79.                                            _m_a_p was allocated.      |
  80.  
  81.      Pixmap          _b_i_t_m_a_p      (in)      Identifier for a  bit-
  82.                                            map    allocated    by
  83.                                            Tk_GetBitmap.
  84. _________________________________________________________________
  85.  
  86.  
  87. DESCRIPTION
  88.      These procedures manage a collection of  bitmaps  (one-plane
  89.      pixmaps) being used by an application.  The procedures allow
  90.      bitmaps to be re-used efficiently, thereby  avoiding  server
  91.      overhead,  and also allow bitmaps to be named with character
  92.      strings.
  93.  
  94.      Tk_GetBitmap takes as argument a Tk_Uid describing a bitmap.
  95.      It returns a Pixmap identifier for a bitmap corresponding to
  96.      the description.  It re-uses an existing bitmap,  if  possi-
  97.      ble,  and  creates a new one otherwise.  At present, _i_d must
  98.      have one of the following forms:
  99.  
  100.      @_f_i_l_e_N_a_m_e           _F_i_l_e_N_a_m_e must be the name of a file con-
  101.                          taining  a  bitmap  description  in  the
  102.                          standard X11 or X10 format.
  103.  
  104.      _n_a_m_e                _N_a_m_e  must  be  the  name  of  a  bitmap
  105.                          defined   previously   with  a  call  to
  106.                          Tk_DefineBitmap.   The  following  names
  107.                          are pre-defined by Tk:
  108.  
  109.                          error       The  international   "don't"  |
  110.                                      symbol:   a  circle  with  a  |
  111.                                      diagonal line across it.
  112.  
  113.                          gray50      50%  gray:  a   checkerboard
  114.                                      pattern  where  every  other
  115.                                      bit is on.
  116.  
  117.                          gray25      25% gray:  a  pattern  where
  118.                                      25% of the bits are on, con-
  119.                                      sisting of all the bit posi-
  120.                                      tions that can be reached by
  121.                                      a chess knight  starting  at
  122.                                      (0,0).
  123.  
  124.                          hourglass   An hourglass symbol.          |
  125.  
  126.  
  127.  
  128.  
  129. Tk                                                              2
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136. Tk_GetBitmap(3)       Tk Library Procedures
  137.  
  138.  
  139.  
  140.                          info                                           ||
  141.                                      A large letter ``i''.         |
  142.  
  143.                          quest-  |
  144.                                      head                                      ||
  145.                                      The silhouette  of  a  human  |
  146.                                      head,  with  a question mark  |
  147.                                      in it.                        |
  148.  
  149.                          ques-  |
  150.                                      tion                                       ||
  151.                                      A large question-mark.        |
  152.  
  153.                          warn-  |
  154.                                      ing                                        ||
  155.                                      A large exclamation point.
  156.  
  157.  
  158.      Under normal conditions, Tk_GetBitmap returns an  identifier
  159.      for  the  requested  bitmap.  If an error occurs in creating
  160.      the bitmap, such as when _i_d refers to a  non-existent  file,
  161.      then  None  is  returned  and  an  error  message is left in
  162.      _i_n_t_e_r_p->_r_e_s_u_l_t.
  163.  
  164.      Tk_DefineBitmap associates a name with in-memory bitmap data  |
  165.      so that the name can be used in later calls to Tk_GetBitmap.  |
  166.      The _n_a_m_e_I_d argument gives a name for the  bitmap;   it  must  |
  167.      not  previously have been used in a call to Tk_DefineBitmap.  |
  168.      The arguments _s_o_u_r_c_e, _w_i_d_t_h, and _h_e_i_g_h_t describe the bitmap.  |
  169.      Tk_DefineBitmap normally returns TCL_OK;  if an error occurs  |
  170.      (e.g. a bitmap named _n_a_m_e_I_d has already been  defined)  then  |
  171.      TCL_ERROR  is  returned  and  an  error  message  is left in  |
  172.      _i_n_t_e_r_p->_r_e_s_u_l_t.  Note:  Tk_DefineBitmap expects  the  memory  |
  173.      pointed  to by _s_o_u_r_c_e to be static:  Tk_DefineBitmap doesn't  |
  174.      make a private copy of  this  memory,  but  uses  the  bytes  |
  175.      pointed to by _s_o_u_r_c_e later in calls to Tk_GetBitmap.
  176.  
  177.      Typically Tk_DefineBitmap is used by #include-ing  a  bitmap
  178.      file  directly  into  a  C  program and then referencing the
  179.      variables defined by the file.  For example,  suppose  there
  180.      exists  a  file stip.bitmap, which was created by the bitmap
  181.      program and contains a stipple pattern.  The following  code
  182.      uses Tk_DefineBitmap to define a new bitmap named foo:
  183.           Pixmap bitmap;
  184.           #include "stip.bitmap"
  185.           Tk_DefineBitmap(interp, Tk_GetUid("foo"), stip_bits,
  186.                           stip_width, stip_height);
  187.           ...
  188.           bitmap = Tk_GetBitmap(interp, tkwin, Tk_GetUid("foo"));
  189.      This code causes the bitmap file to be read at  compile-time
  190.      and  incorporates  the bitmap information into the program's
  191.      executable image.  The same bitmap file  could  be  read  at
  192.  
  193.  
  194.  
  195. Tk                                                              3
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202. Tk_GetBitmap(3)       Tk Library Procedures
  203.  
  204.  
  205.  
  206.      run-time using Tk_GetBitmap:
  207.           Pixmap bitmap;
  208.           bitmap = Tk_GetBitmap(interp, tkwin, Tk_GetUid("@stip.bitmap"));
  209.      The second form is a bit more flexible (the  file  could  be
  210.      modified after the program has been compiled, or a different
  211.      string could be provided to read a different file),  but  it
  212.      is  a  little  slower  and requires the bitmap file to exist
  213.      separately from the program.
  214.  
  215.      Tk_GetBitmap maintains a database of all  the  bitmaps  that
  216.      have  been  created.   Whenever  possible, it will return an
  217.      existing bitmap  rather  than  creating  a  new  one.   This
  218.      approach   can  substantially  reduce  server  overhead,  so
  219.      Tk_GetBitmap should generally be used in preference to  Xlib
  220.      procedures like XReadBitmapFile.
  221.  
  222.      The bitmaps returned by Tk_GetBitmap are shared, so  callers
  223.      should  never  modify  them.   If  a bitmap must be modified
  224.      dynamically, then it should be created by calling Xlib  pro-
  225.      cedures such as XReadBitmapFile or XCreatePixmap directly.
  226.  
  227.      The procedure Tk_NameOfBitmap  is  roughly  the  inverse  of
  228.      Tk_GetBitmap.  Given an X Pixmap argument, it returns the _i_d
  229.      that was passed to Tk_GetBitmap when the bitmap was created.  |
  230.      _B_i_t_m_a_p  must have been the return value from a previous call  |
  231.      to Tk_GetBitmap.
  232.  
  233.      Tk_SizeOfBitmap returns the dimensions of its  _b_i_t_m_a_p  argu-  |
  234.      ment  in  the words pointed to by the _w_i_d_t_h_P_t_r and _h_e_i_g_h_t_P_t_r  |
  235.      arguments.  As with Tk_NameOfBitmap, _b_i_t_m_a_p must  have  been  |
  236.      created by Tk_GetBitmap.
  237.  
  238.      When a bitmap returned by Tk_GetBitmap is no longer  needed,
  239.      Tk_FreeBitmap  should be called to release it.  There should
  240.      be exactly one  call  to  Tk_FreeBitmap  for  each  call  to
  241.      Tk_GetBitmap.   When  a  bitmap is no longer in use anywhere
  242.      (i.e. it has been freed as many times as it has been gotten)
  243.      Tk_FreeBitmap  will release it to the X server and delete it
  244.      from the database.
  245.  
  246.  
  247. BUGS
  248.      In determining whether an existing bitmap  can  be  used  to
  249.      satisfy  a  new  request,  Tk_GetBitmap  considers  only the
  250.      immediate value of its _i_d argument.   For  example,  when  a
  251.      file  name  is  passed  to  Tk_GetBitmap,  Tk_GetBitmap will
  252.      assume it is safe to re-use an existing bitmap created  from
  253.      the  same  file  name:  it will not check to see whether the
  254.      file itself has changed, or whether  the  current  directory
  255.      has  changed,  thereby  causing  the name to refer to a dif-
  256.      ferent file.
  257.  
  258.  
  259.  
  260.  
  261. Tk                                                              4
  262.  
  263.  
  264.  
  265.  
  266.  
  267.  
  268. Tk_GetBitmap(3)       Tk Library Procedures
  269.  
  270.  
  271.  
  272. KEYWORDS
  273.      bitmap, pixmap
  274.  
  275.  
  276.  
  277.  
  278.  
  279.  
  280.  
  281.  
  282.  
  283.  
  284.  
  285.  
  286.  
  287.  
  288.  
  289.  
  290.  
  291.  
  292.  
  293.  
  294.  
  295.  
  296.  
  297.  
  298.  
  299.  
  300.  
  301.  
  302.  
  303.  
  304.  
  305.  
  306.  
  307.  
  308.  
  309.  
  310.  
  311.  
  312.  
  313.  
  314.  
  315.  
  316.  
  317.  
  318.  
  319.  
  320.  
  321.  
  322.  
  323.  
  324.  
  325.  
  326.  
  327. Tk                                                              5
  328.  
  329.  
  330.  
  331.